package com.hilon.segment.mybatis.pojo.dto;

import lombok.Data;
import org.springframework.security.access.AccessDecisionManager;
import org.springframework.security.core.GrantedAuthority;

@Data
public class MyGrantedAuthorityDTO implements GrantedAuthority {


    private String method;

    private String url;

    // 此处的权限为请求类型 + 请求Url.
    private String authority;

    public MyGrantedAuthorityDTO() {
    }

    public MyGrantedAuthorityDTO(String method, String url, String authority) {
        this.method = method;
        this.url = url;
        this.authority = authority;
    }

    /**
     * If the <code>GrantedAuthority</code> can be represented as a <code>String</code>
     * and that <code>String</code> is sufficient in precision to be relied upon for an
     * access control decision by an {@link AccessDecisionManager} (or delegate), this
     * method should return such a <code>String</code>.
     * <p>
     * If the <code>GrantedAuthority</code> cannot be expressed with sufficient precision
     * as a <code>String</code>, <code>null</code> should be returned. Returning
     * <code>null</code> will require an <code>AccessDecisionManager</code> (or delegate)
     * to specifically support the <code>GrantedAuthority</code> implementation, so
     * returning <code>null</code> should be avoided unless actually required.
     *
     * @return a representation of the granted authority (or <code>null</code> if the
     * granted authority cannot be expressed as a <code>String</code> with sufficient
     * precision).
     */
    @Override
    public String getAuthority() {
        return this.authority;
    }
}
